﻿using BodaNetCommunications.Extensions;
using BodaNetCommunications.Utilities.ComTypes;

namespace BodaNetCommunications.Nodes
{
    public class RequestNode : IRequestNode
    {
        public long DeviceId { get; set; }
        public int Index { get; set; }
        public string? DataFieldName { get; set; }
        public int Interval { get; set; }
        public DataType? PlcDataFormat { get; set; }
        public string? NodeAddress { get; set; }
        public int Db { get; set; }
        public int StartAddr { get; set; }
        public int Count { get; set; }
        public byte Bit { get; set; }
        public ReadTypeEnum ReadType { get; set; }

        /// <summary>
        /// 上一次的数据
        /// </summary>
        private object? _readVarValue;
        public object? ReadVarValue
        {
            get { return _readVarValue; }
            set
            {
                _readVarValue = value;
            }
        }

        /// <summary>
        /// 前一次的数据
        /// </summary>
        public object? ReadVarPreValue { get; set; }

        /// <summary>
        /// 判断数据是否发生变化
        /// </summary>
        private bool _readValueChanged;
        public bool ReadValueChanged
        {
            get
            {
                _readValueChanged = ReadVarValue.ObjEquals(ReadVarPreValue);
                return _readValueChanged;
            }
            set { _readValueChanged = value; }
        }

        public bool Offline { get; set; }
        public DeviceValueTypeEnum? ReadVarType { get; set; }
        public object? WriteVarValue { get; set; }
        public string? ExtraProperty { get; set; }
        public string? Remark { get; set; }
        public string? Group { get; set; }

        public FunctionCodeEnum? FunctionCode { get; set; }

        public EndianType EndianType { get; set; }
        public string? Message { get; set; }

        /// <summary>
        /// 相同类别的区分（比如层压机的腔体）
        /// </summary>
        public string? Category { get; set; }



        /// <summary>
        /// 是否触发的节点
        /// </summary>
        public bool TriggerNode { get; set; }
        /// <summary>
        /// 触发事件的名称，包含了触发节点和非触发节点
        /// </summary>
        public string? EventName { get; set; }

        /// <summary>
        /// 设备号
        /// </summary>
        public string? DeviceCode { get; set; }

        /// <summary>
        /// 是否周期采集节点
        /// </summary>
        public bool IsPeriodicNode { get; set; }

        /// <summary>
        /// 是否状态节点
        /// </summary>
        public bool IsStateNode { get; set; }

        /// <summary>
        /// 是否报警节点
        /// </summary>
        public bool IsAlarmNode { get; set; }


        public double TimeCost { get; set; }
    }
}
